package com.wx.msg;

import java.util.Date;
import java.util.List;

import com.wx.msg.resp.Article;
import com.wx.msg.resp.ImageMsg;
import com.wx.msg.resp.Media;
import com.wx.msg.resp.NewsMsg;
import com.wx.msg.resp.TextMsg;
import com.wx.type.MsgType;
import com.wx.util.MsgUtil;

/**
 * 
 * 
 * @author jiangyin
 */
public class MessageResponse {

	/**
	 * 回复文本消息
	 * 
	 * @param fromUserName
	 * @param toUserName
	 * @param respContent
	 * @return
	 */
	public static String getTextMessage(String fromUserName, String toUserName,
			String respContent) {

		TextMsg textMessage = new TextMsg();
		textMessage.setToUserName(fromUserName);
		textMessage.setFromUserName(toUserName);
		textMessage.setCreateTime(new Date().getTime());
		textMessage.setMsgType(MsgType.RESP_MESSAGE_TYPE_TEXT);
		textMessage.setFuncFlag(0);

		textMessage.setContent(respContent);
		return MsgUtil.textMessageToXml(textMessage);
	}

	/**
	 * 创建图文消息
	 * 
	 * @param fromUserName
	 * @param toUserName
	 * @param articleList
	 * @return
	 */
	public static String getNewsMessage(String fromUserName, String toUserName,
			List<Article> articleList) {

		NewsMsg newsMessage = new NewsMsg();
		newsMessage.setToUserName(fromUserName);
		newsMessage.setFromUserName(toUserName);
		newsMessage.setCreateTime(new Date().getTime());
		newsMessage.setMsgType(MsgType.RESP_MESSAGE_TYPE_NEWS);
		newsMessage.setFuncFlag(0);

		// 设置图文消息个数
		newsMessage.setArticleCount(articleList.size());
		// 设置图文消息包含的图文集合
		newsMessage.setArticles(articleList);
		// 将图文消息对象转换成xml字符串
		return MsgUtil.newsMessageToXml(newsMessage);
	}

	public static String getImageMessage(String fromUserName, String toUserName,
			String mediaId) {

		ImageMsg msg = new ImageMsg();
		msg.setToUserName(fromUserName);
		msg.setFromUserName(toUserName);
		msg.setCreateTime(new Date().getTime());
		msg.setMsgType(MsgType.REQ_MESSAGE_TYPE_IMAGE);
		msg.setFuncFlag(0);
		
		Media image = new Media();
		image.setMediaId(mediaId);
		msg.setImage(image);

		// 将图文消息对象转换成xml字符串
		return MsgUtil.imageMessageToXml(msg);
	}
}